<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/13 0013
 * Time: 上午 10:48
 */

namespace ToolClass;

use Illuminate\Support\Facades\DB;
class PageClass
{
    public static function Page($table,$limit,$where,$page){

        if(!empty($where)){
            $count = DB::table($table)->where($where)->count();
        }else{
            $count = DB::table($table)->count();
        }


        $totalPage = ceil($count/$limit);

        if($page==''||$page>$totalPage||$page<=0){

            $page = 1;
        }
        $startCount=($page-1)*$limit;
        if(!empty($where)) {
            $data = DB::table($table)->where($where)->offset($startCount)->limit($limit)->get();
        }else{
            $data = DB::table($table)->offset($startCount)->limit($limit)->get();
        }
        $r = array($data,$totalPage);
        return $r;
    }
}